<template>
	<view class="page">
		<view class="head-box">
			<img src="../../static/image/my-bg.jpg" alt="" style="width: 100%; height: 224rpx; " >
			<view class="info" v-if="!isAuthor" @click="addAuthor">
				<img src="../../static/image/touxiang.png" alt="">
				<view class="name">点击登录</view>
			</view>
			<view class="info" v-if=" isAuthor">
				<img :src="photo" alt="">
				<view class="name">{{nikeName}}</view>
			</view>
		</view>
		
		<view class="action-list">
			<view class="item" @click="jumpInquiry">
				<view class="left">
					<img src="../../static/image/xunjia.png" alt="">
					<view class="text">我的询价</view>
				</view>
				<view class="right">
					<img src="../../static/image/right.png" alt="">
				</view>
			</view>
			
			<view class="item" @click="jumpMount" >
				<view class="left">
					<img src="../../static/image/mount.png" alt="">
					<view class="text">挂载中心</view>
				</view>
				<view class="right">
					<img src="../../static/image/right.png" alt="">
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const Api = require('../../utils/api.js');
	const request = require('../../utils/request.js');
	export default {
		data() {
			return {
				photo:  uni.getStorageSync('photo'),
				nikeName: uni.getStorageSync('nickname'),
				isLogin: false,
				userInfo: {},
				type: '',
				is_kol: false,
				isAuthor: false
			}
		},
		onLoad () {
		},
		onShow() {
			this.isLogin = uni.getStorageSync('token') != '' ?  true : false
			this.type =uni.getStorageSync('signature') == '' ? '未设置' : '已设置'
			this.isAuthor =uni.getStorageSync('is_author')
			console.log(this.isAuthor, 'www')
		
		},
		methods: {
			addAuthor(){
				let _this = this
				wx.getUserProfile({
				  success(res) {
					console.log(res, "33")
					_this.isAuthor = true
					_this.nikeName = res.userInfo.nickName
					_this.photo = res.userInfo.avatarUrl
					_this.userInfo = res
					uni.setStorageSync('photo', res.userInfo.avatarUrl)
					uni.setStorageSync('nickname', res.userInfo.nickName)
					uni.setStorageSync('is_author', true)
					_this.updataInfo()
				  },
				  fail(res) { 
					console.log("getUserProfile 调用失败", res);
				  },
				});
			},
			jumpInquiry() {
				if(!this.isAuthor) {
					this.addAuthor()
					return
				}
				uni.navigateTo({
					url:'/subPackage/personal/myInquiry'
				})
				
			
			},
			jumpMount() {
				if(!this.isAuthor) {
					this.addAuthor()
					return
				}
				
				
				if(uni.getStorageSync('account_hid') == ''){
					uni.navigateTo({
						url:'/subPackage/personal/binding'
					})
					return
				}				
				//创建挂载记录
				request.http({
					url:Api.mount_create,
					header: {
						// 'content-type': 'application/x-www-form-urlencoded',
						'token':uni.getStorageSync('token')
					},
					type: 'POST',
					data: {
						account_hid: uni.getStorageSync('account_hid')
					},
				}).then(res => {
					console.log("创建挂载")
					uni.navigateTo({
						url:'/subPackage/personal/mount?mount_log_hid='+ res.data.hid
					})
				})
			},
			
			
			//更新头像
			updataInfo () {
				request.http(
				{
					url: Api.user_update,
					type: 'POST',
					header: {
						// // 'content-type': 'application/x-www-form-urlencoded',
						'token':uni.getStorageSync('token')
					},
					data: {
						encrypted_data: this.userInfo.encryptedData,
						iv: this.userInfo.iv,
						raw_data: this.userInfo.rawData,
						signature: this.userInfo.signature
					},
					}).then(result=>{
						console.log(result)
					})
			}
		}
	}
</script>

<style lang="scss" scoped>
	 .page {
		height: 94.5vh;
		overflow-y: hidden;
		padding: 36rpx 21rpx;
		background: #fff;
	 }
	.head-box{
	height: 240rpx;
	position: relative;
	.info{
		display: flex;
		align-items: center;
		position: absolute;
		top: 54rpx;
		left: 29rpx;
		img {
			width: 115rpx;
			height: 115rpx;
			border-radius: 50%;
			margin-right: 28rpx;
		}
		.name {
			font-weight: 600;
			color: #FFFFFF;
			font-size: 36rpx;
		}
	}
}
	.action-list {
		// height: 100vh;
		padding:20rpx 0;
		.item {
			// background: #fff;
			height: 128rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			img{
				width: 43rpx;
				height: 43rpx;
			}
			.left {
				display: flex;
				align-items: center;
				.text {
					margin-left: 21rpx;
					font-size: 31rpx;
					color: #021615;
				}
			}

			.right {
				display: flex;
				align-items: center;
				.text {
					font-weight: 400;
					color: #6E7175;
					font-size: 27rpx;
				}
			}
		}
	}
</style> 